package com.project.controller;

import com.project.entity.BaseResult;
import com.project.entity.Customer;
import com.project.mapper.CustomerMapper;
import com.project.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private CustomerMapper customerMapper;

    @PostMapping("/show")
    public BaseResult<List<Customer>> show(){
        List<Customer> customers= customerMapper.selectList(null);;
        return BaseResult.ok(customers);
    }
    @PostMapping("/edit")
    public BaseResult<String> edit(@RequestBody Customer customer){
        customerService.updateById(customer);
        return BaseResult.ok("更新成功");
    }
    @PostMapping("add")
    public BaseResult<String> add(HttpServletRequest request, @RequestBody Customer customer){
        log.info("添加的用户信息：{}",customer.toString());
        customerService.save(customer);
        return BaseResult.ok("用户添加成功");
    }

}
